package com.ohyes.bigbang.syscfg.menu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ohyes.bigbang.syscfg.menu.mapper.MenuMapper;
import com.ohyes.bigbang.syscfg.menu.po.Menu;

@Service
public class MenuService implements IMenuService {

	@Autowired
	MenuMapper menuMapper;

	/* (non-Javadoc)
	 * @see com.ohyes.bigbang.syscfg.menu.service.IMenuService#getMenuTree(int)
	 */
	@Override
	public List<Menu> getMenuTree(int id) {
		List<Menu> list = menuMapper.getMenuTree(id);
		for (Menu menu : list) {
			if (menu.getLeaf() == 0) {
				menu.setExpanded("true");
			}
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.ohyes.bigbang.syscfg.menu.service.IMenuService#getMenu(int)
	 */
	@Override
	public Menu getMenu(int id) {
		return menuMapper.getMenu(id);
	}

	/* (non-Javadoc)
	 * @see com.ohyes.bigbang.syscfg.menu.service.IMenuService#add(com.ohyes.bigbang.syscfg.menu.po.Menu)
	 */
	@Override
	@Transactional
	public void add(Menu menu) {
		menuMapper.save(menu);
	}

	/* (non-Javadoc)
	 * @see com.ohyes.bigbang.syscfg.menu.service.IMenuService#update(com.ohyes.bigbang.syscfg.menu.po.Menu)
	 */
	@Override
	@Transactional
	public void update(Menu menu) {
		menuMapper.update(menu);
//		String s = null;
//		System.out.println(s.charAt(1));

	}

	/* (non-Javadoc)
	 * @see com.ohyes.bigbang.syscfg.menu.service.IMenuService#delete(int)
	 */
	@Override
	@Transactional
	public void delete(int id) {
		menuMapper.delete(id);
//		String s = null;
//		System.out.println(s.charAt(1));
	}

}
